package com.igeek.blog_parent_test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeek.blog_parent_test.entity.Users;
import com.igeek.blog_parent_test.mapper.UsersMapper;
import com.igeek.blog_parent_test.service.IUsersService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.igeek.blog_parent_test.vo.PageQueryVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-12-04
 */
@Service
public class UsersServiceImpl extends ServiceImpl<UsersMapper, Users> implements IUsersService {

   @Transactional(readOnly = true)
    @Override
    public Page<Users> findPage(PageQueryVO vo) {
       Integer currentPage = vo.getCurrentPage();
       Integer pageSize = vo.getPageSize();
       Page<Users> page = Page.of(currentPage, pageSize);

       String queryString = vo.getQueryString();
       LambdaQueryWrapper<Users> lambdaQueryWrapper=new LambdaQueryWrapper<>();
       lambdaQueryWrapper.eq(StringUtils.hasLength(queryString),Users::getUserId,queryString)
               .or()
               .like(StringUtils.hasLength(queryString),Users::getUsername,queryString);
       Page<Users> usersPage = this.baseMapper.selectPage(page, lambdaQueryWrapper);
       return usersPage;
    }
@Transactional
    @Override
    public boolean del(Integer userId) {
        return false;
    }
}
